[Exercise 1.4]

The program we have written will make the LED flash. If you run the program at the speed of the crystal clock you will not see a flashing LED, you will see a glowing one.

What is required is a way of "pausing" the processor once the LED has been switched on. Unfortunately we can't do this, but we can keep it busy with a loop. To do this you will need to make a for loop which does nothing. The PICmicro will run this, and it will provide a pause in the execution of the program.

I have used a for loop to give a nice big delay. I has also used an integer as the counter. This slows things down in two ways, we can count to a larger limit if we use integers, and the actual mathematics takes longer with integer variables.

If you run this program on the PICmicro you will find that the LED flashes at around 6 Hz.

Please note to run this program you will need to set the PICmicro RC/XTAL switch to XTAL.

The flasher seems to spend the same amount of time on as off now. This is because the time taken to perform the while loop is insignificant as compared to the time taken in the two delay loops.

The for loop is a way of performing an action a given number of times. To find out more click here

Note that I am using the same colour coding as the MPLAB X IDE environment will use:

grey - a comment

blue - a part of the C language: a keyword

green - pre-processor directive

orange - external files and strings